﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace MMDemo
{
    public class PlayMedia
    {
        [DllImport("winmm.dll")]
        public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);

        private string Path = "";
        public void SetMusicPath(string path)
        {
            this.Path = path;
        }
        public void PlaySong()
        {
            mciSendString("close media", null, 0, 0);//关闭
            mciSendString("open \"" + Path + "\" type mpegvideo alias media", null, 0, 0);
            mciSendString("play media repeat", null, 0, 0);//播放
        }
        public void CloseSong()
        {
            mciSendString("close media", null, 0, 0);//关闭
        }
        public void PauseSong()
        {
            mciSendString("pause media", null, 0, 0);
        }
        public void ResumeSong()
        {
            mciSendString("resume media", null, 0, 0);
        }
        public void StopSong()
        {
            mciSendString("stop media", null, 0, 0);
        }
    }
}
